package bpd;

import junit.framework.TestCase;

/**
 * The TestMoveToCenter class creates three MoveToCenter objects and tests the algorithm used to
 * move a robot to the center of a battlefield by calling their methods.
 * 
 * @author BJ Peter DeLaCruz
 * @version 1.0
 * 
 */
public class TestMoveToCenter extends TestCase {

  /** An 800x600 battlefield. */
  private MoveToCenter testCase1;
  /** A 300x900 battlefield. */
  private MoveToCenter testCase2;
  /** A 1200x200 battlefield. */
  private MoveToCenter testCase3;
  
  /**
   * Calls the superclass constructor in TestCase to construct a test case with the given name.
   * 
   * @param name Name of the test case
   */
  public TestMoveToCenter(String name) {
    super(name);
  }
  
  /**
   * Creates three battlefields and puts a robot at a random location in each battlefield.
   */
  public void setUp() {
    testCase1 = new MoveToCenter(800.0, 600.0, 100.0, 200.0);
    testCase2 = new MoveToCenter(300.0, 900.0, 45.0, 777.0);
    testCase3 = new MoveToCenter(1200.0, 200.0, 12.0, 12.0);
  }
  
  /**
   * Tests each of the three battlefields to see if the center of each battlefield is calculated
   * correctly.
   */
  public void testMoveToCenterX() {
    
    // Use the initial positions that were passed into the constructors.
    System.out.println("\n\nCenter of battlefield testCase1 is X: 400, Y: 300...");
    System.out.println("Initial position of robot is X: 100, Y: 200...");
    assertEquals("Checking X for testCase1", 300.0, testCase1.moveToCenterX());
    assertEquals("Checking Y for testCase1", 100.0, testCase1.moveToCenterY());
    System.out.println("Distance to center is X: 300, Y: 100... OK.\n");
    
    System.out.println("Center of battlefield testCase2 is X: 150, Y: 450...");
    System.out.println("Initial position of robot is X: 45, Y: 777...");
    assertEquals("Checking X for testCase2", 105.0, testCase2.moveToCenterX());
    assertEquals("Checking Y for testCase2", 327.0, testCase2.moveToCenterY());
    System.out.println("Distance to center is X: 105, Y: 327... OK.\n");
    
    System.out.println("Center of battlefield testCase3 is X: 600, Y: 100...");
    System.out.println("Initial position of robot is X: 12, Y: 12...");
    assertEquals("Checking X for testCase3", 588.0, testCase3.moveToCenterX());
    assertEquals("Checking Y for testCase3", 88.0, testCase3.moveToCenterY());
    System.out.println("Distance to center is X: 588, Y: 88... OK.\n");
    
    // Use setters and change the positions to different values.
    System.out.println("Changing initial positions of robots...\n");
    testCase1.setPositionX(400.0);
    testCase1.setPositionY(300.0);
    testCase2.setPositionX(77.0);
    testCase2.setPositionY(450.0);
    testCase3.setPositionX(600.0);
    testCase3.setPositionY(101.0);
    
    System.out.println("Center of battlefield testCase1 is X: 400, Y: 300...");
    System.out.print("Initial position of robot is X: " + testCase1.getPositionX() + ", Y: ");
    System.out.println(testCase1.getPositionY());
    assertEquals("Checking X for testCase1", 0.0, testCase1.moveToCenterX());
    assertEquals("Checking Y for testCase1", 0.0, testCase1.moveToCenterY());
    System.out.println("Distance to center is X: 0, Y: 0... OK.\n");
    
    System.out.println("Center of battlefield testCase2 is X: 150, Y: 450...");
    System.out.print("Initial position of robot is X: " + testCase2.getPositionX() + ", Y: ");
    System.out.println(testCase2.getPositionY());
    assertEquals("Checking X for testCase2", 73.0, testCase2.moveToCenterX());
    assertEquals("Checking Y for testCase2", 0.0, testCase2.moveToCenterY());
    System.out.println("Distance to center is X: 73, Y: 0... OK.\n");
    
    System.out.println("Center of battlefield testCase3 is X: 600, Y: 100...");
    System.out.print("Initial position of robot is X: " + testCase3.getPositionX() + ", Y: ");
    System.out.println(testCase3.getPositionY());
    assertEquals("Checking X for testCase3", 0.0, testCase3.moveToCenterX());
    assertEquals("Checking Y for testCase3", 1.0, testCase3.moveToCenterY());
    System.out.println("Distance to center is X: 0, Y: 1... OK.\n");
    
  }

}
